﻿using System.Windows.Controls;
using FarseerGames.FarseerPhysics.Mathematics;
using FreeGoo.GameEngine.Renderables;

namespace FreeGoo.WpfRenderer
{
    public class ImageRenderer : RendererWithCanvas
    {
        private Vector2 _offset;
        public ImageRenderer(RendererFactory factory, Renderable renderable, Image image, Vector2 offset)
            : base(factory, renderable)
        {
            Image = image;
            SetCanvasContent(image);
            Offset = offset;
            StateChanged();
        }

        public Image Image { get; set; }
        public Vector2 Offset
        {
            get
            {
                return _offset;
            }

            set
            {
                _offset = value;
                AdjustOffset();
            }
        }

        public override void StateChanged()
        {
        }
        
        public void AdjustOffset()
        {
            Image.SetValue(Canvas.LeftProperty, -Image.Width * 0.5f + _offset.X);
            Image.SetValue(Canvas.TopProperty, -Image.Height * 0.5f + _offset.Y);
        }
    }
}
